﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Proje
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void addStopPoint_Click(object sender, EventArgs e)
        {
            liste.Items.Add(String.Format("{0}|{1}", startPoint.Text, startTime.Text));
            

            stopPoint.Enabled = true;
            stopPointTime.Enabled = true;
            liste.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            liste.Items.Add(String.Format("{0}|{1}", stopPoint.Text, stopPointTime.Text));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            liste.Items.Add(String.Format("{0}|{1}", endPoint.Text, stopTime.Text));

            Route route = new Route();

            route.number = Convert.ToInt32(routeId.Text);
            route.date = date.Text;
            route.bus = bus.Text;

            foreach (var item in liste.Items)
            {
                String str = (string)item;
                StopPoint p = new StopPoint();
                p.name = str.Split('|')[0];
                p.time = str.Split('|')[1];
                route.stopPoints.Add(p);
            }

            RouteFileConnector routeConnector = new RouteFileConnector();

            if (routeConnector.insert(route))
            {
                MessageBox.Show("Sefer Eklendi.");
            }
            else
            {
                MessageBox.Show("Sefer Eklenemedi.");
            }
        }
    }
}
